package com.zzl.bonds.ticket.controller;

import com.zzl.apidoc.annotation.ApidocController;
import com.zzl.apidoc.annotation.ApidocOperation;
import com.zzl.apidoc.annotation.ApidocParam;
import com.zzl.bonds.ticket.dto.TickeprotocolAddDto;
import com.zzl.bonds.ticket.dto.TickeprotocolUpdateDto;
import com.zzl.bonds.ticket.entity.TicketProtocolEntity;
import com.zzl.bonds.ticket.service.TicketProtocolService;
import com.zzl.general.common.apidoc.annotation.ApidocParamsPage;
import com.zzl.general.common.apidoc.annotation.ApidocResultKeyValR;
import com.zzl.general.common.apidoc.annotation.ApidocReturnPage;
import com.zzl.general.common.apidoc.annotation.ApidocReturnR;
import com.zzl.general.common.apidoc.constants.ResultTypeInR;
import com.zzl.general.common.ctrl.WebBaseCtrl;
import com.zzl.general.common.exception.SysException;
import com.zzl.general.common.utils.LogUtils;
import com.zzl.general.common.utils.PageUtils;
import com.zzl.general.common.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;
/**
 * 开立或转让签订的协议
 *
 * @author sunpp
 * @date 2022-02-16 11:14:07
 */
@ApidocController("开立或转让签订的协议")
@RestController
@SuppressWarnings("javadoc")
@RequestMapping("bondsticket/tickeprotocol")
@Slf4j
public class TickeprotocolController extends WebBaseCtrl {
    @SuppressWarnings("all")
    @Autowired
    private TicketProtocolService ticketProtocolService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApidocOperation(description = "分页查询开立或转让签订的协议数据", operationId = "4001")
    @ApidocReturnPage(genericTypeClass = TicketProtocolEntity.class)
    public Result list(@ApidocParamsPage(name = "params") @RequestParam Map<String, Object> params){
        PageUtils page = ticketProtocolService.queryPage(params);
        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApidocOperation(description = "通过id获取开立或转让签订的协议数据", operationId = "4002")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_OBJECT, key = "tickeprotocol", valueClass = TicketProtocolEntity.class)
    })
    public Result info(@ApidocParam(name = "开立或转让签订的协议id", required = true) @PathVariable("id") String id){
		TicketProtocolEntity tickeprotocol = ticketProtocolService.getById(id);
        return Result.ok().put("tickeprotocol", tickeprotocol);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApidocOperation(description = "保存开立或转让签订的协议", operationId = "4003")
    @ApidocReturnR
    public Result save(@ApidocParam(name = "保存的开立或转让签订的协议对象值", required = true) @RequestBody TickeprotocolAddDto tickeprotocol){
        try {
            ticketProtocolService.saveTickeprotocol(tickeprotocol, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApidocOperation(description = "修改开立或转让签订的协议", operationId = "4004")
    @ApidocReturnR
    public Result update(@ApidocParam(name = "修改的开立或转让签订的协议对象值", required = true) @RequestBody TickeprotocolUpdateDto tickeprotocol){
        try {
            ticketProtocolService.updateTickeprotocolById(tickeprotocol, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApidocOperation(description = "删除开立或转让签订的协议", operationId = "4005")
    @ApidocReturnR
    public Result delete(@ApidocParam(name = "删除的开立或转让签订的协议对象id集合", required = true) @RequestBody String[] ids){
		ticketProtocolService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
